#include "MyWorkThread.h"
#include "wxMYPictureFrame.h"
#include "GaussianImageFilter.h"
#include <time.h>

MyThread::MyThread(wxFrame* Frame,std::string&_implement)
:wxThread(wxTHREAD_JOINABLE),
myMainFrame(Frame),
implement(_implement)
{
}


void* MyThread::Entry()
{
	//(((wxMYPictureFrame*)myMainFrame)->myTimer).Stop();
	ImageProcessing::GaussianImageFilter *GaussProcess= new ImageProcessing::GaussianImageFilter(4/*, "Linear_CUDA"*/);
	string _impl = GaussProcess->GetImplementation(); 
	wxMutexGuiEnter();
	NOVA::Image * tmp = ((wxMYPictureFrame*)myMainFrame)->GetImage();
	wxMutexGuiLeave();
	if(  _impl !="Linear_CPP")
	{
		 wxMutexGuiEnter();
		(((wxMYPictureFrame*)myMainFrame)->myTimer).Stop();
		 GaussProcess->Run(tmp,7);
		 wxMutexGuiLeave();
	}
	else GaussProcess->Run(tmp,7);
	 delete GaussProcess;
	 return NULL;
}
void MyThread::OnExit()
{
	 wxMutexGuiEnter();
	(((wxMYPictureFrame*)myMainFrame)->myTimer).Stop();
	//((wxMYPictureFrame*)myMainFrame)->Refresh();
	//((wxMYPictureFrame*)myMainFrame)->GetMenuBar()->Enable(1011u,true);
	time_t t_end;
	time(&t_end);
	char t[10];
	sprintf_s(t,"%d",t_end-((wxMYPictureFrame*)myMainFrame)->GetTime());
	myMainFrame->SetTitle(_T(string("multi thread ..finished......"))+t+" seconds");

	 wxMutexGuiLeave();
	OutputDebugStringA("wrok thread finished");
}
